# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lapce
pkgver=0.3.0
pkgrel=0
pkgdesc="Lightning-fast and Powerful Code Editor written in Rust"
url="https://lapce.dev"
# armhf, armv7, x86: wasmer-vm crate fails to build (unsupported platform)
# ppc64le: ring crate fails to build
# riscv64: would take eternity to build
# s390x: no desktop on this arch
arch="aarch64 x86_64"
license="Apache-2.0"
makedepends="
	cargo
	cargo-auditable
	cmd:patchelf
	libgit2-dev
	libssh2-dev
	libxkbcommon-dev
	openssl-dev
	vulkan-loader-dev
	wayland-dev
	zstd-dev
	"
subpackages="$pkgname-proxy"
source="https://github.com/lapce/lapce/archive/v$pkgver/lapce-$pkgver.tar.gz
	use-system-libs.patch
	cargo.lock.patch
	"
options="!check"  # no tests provided

export CARGO_PROFILE_RELEASE_OPT_LEVEL=2

export LIBSSH2_SYS_USE_PKG_CONFIG=1  # use system libssh2

prepare() {
	default_prepare

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided libgit2 and libzstd.
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		git2 = { rustc-link-lib = ["git2"] }
		zstd = { rustc-link-lib = ["zstd"] }
	EOF

	cargo fetch --target="$CTARGET" --locked
}

build() {
	export RELEASE_TAG_NAME="$pkgver"

	# Exclude feature all-languages and updater.
	cargo auditable build -p lapce-app --frozen --release --no-default-features

	cargo auditable build -p lapce-proxy --frozen --release

	# Add missing vulkan dependency.
	patchelf --add-needed libvulkan.so.1 target/release/lapce
}

package() {
	install -D -m755 target/release/lapce -t "$pkgdir"/usr/bin/
	install -D -m755 target/release/lapce-proxy -t "$pkgdir"/usr/bin/

	install -D -m644 extra/linux/dev.lapce.lapce.desktop -t "$pkgdir"/usr/share/applications/
	install -D -m644 extra/images/logo.svg \
		"$pkgdir"/usr/share/icons/hicolor/scalable/apps/dev.lapce.lapce.svg
}

proxy() {
	pkgdesc="Remote proxy server for the Lapce editor"

	amove usr/bin/lapce-proxy
}

sha512sums="
9eaf0190930a4e582a60bb3ff327944553ca87101c86ca9610650b40a5a45092dd6921842880021393c79ea4ff97ec91bab12e316e6693b7b881b68f6bcb1d6e  lapce-0.3.0.tar.gz
b140ff385e71a0579fff1d8727b6af89cd9c66e3166359b32ecde0d5133fb9247e431f3e3337779f84cac1405409c1292e30606a746b6e96f75cf53d734d6815  use-system-libs.patch
df3bbb931e8c8d79754fd28ca82342177e3bcaaabd00333245f33fbfb37730de13cd73057c4582866498ef113461bb5ceda347ccaba4aee40bdf6eefaa655856  cargo.lock.patch
"
